package cn.com.xcf.spring;

/**
 * @author WongBin
 * @date 2017/11/8.
 */
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class AppContextConfig {
    private static Map<String, String> configHolder = new ConcurrentHashMap();

    public AppContextConfig() {
    }

    public static Map<String, String> getConfigMap() {
        return configHolder;
    }

    public static String get(String key) {
        return (String)configHolder.get(key);
    }

    public static String get(String key, Object defaultVal) {
        return !configHolder.containsKey(key)?"" + defaultVal:(String)configHolder.get(key);
    }

    public static Long getLong(String key, long def) {
        return Long.valueOf(get(key, Long.valueOf(def)));
    }

    public static Double getDouble(String key, double def) {
        return Double.valueOf(get(key, Double.valueOf(def)));
    }

    public static Integer getInteger(String key, int def) {
        return Integer.valueOf(get(key, Integer.valueOf(def)));
    }

    public static Boolean getBoolean(String key, boolean def) {
        return Boolean.valueOf(get(key, Boolean.valueOf(def)));
    }

    public static void put(String key, String val) {
        if(val != null) {
            val = val.trim();
        }

        configHolder.put(key, val);
    }

    public static String remove(String key) {
        return (String)configHolder.remove(key);
    }

    public static String getAppName() {
        return get("app.name");
    }

    public static String getAppEnv() {
        return get("env");
    }
}
